package com.ik.hiddevice;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.os.Bundle;
import android.widget.Toast;

import com.ik.hiddevice.listener.OnBlueScanListener;
import com.ik.hiddevice.listener.OnBondStateChanedListener;
import com.ik.hiddevice.utlis.LogUtil;

public class MainActivity extends BaseActivity implements OnBlueScanListener, OnBondStateChanedListener {

    private BluetoothAdapter mBluetoothAdapter;
    private BlueToothHelper1 blueToothHelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int initLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void permissionHasBeenGranted() {
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (mBluetoothAdapter == null){
            LogUtil.showLogE(TAG,"设备没有蓝牙模块！");
            Toast.makeText(this,"设备没有蓝牙模块！",Toast.LENGTH_SHORT).show();
            finish();
            return;
        }
//        blueToothHelper = new BlueToothHelper();
//        blueToothHelper.setOnBlueScanListener(this);
//        blueToothHelper.setOnBondStateChanedListener(this);
//        blueToothHelper.start(this,mBluetoothAdapter);
        blueToothHelper = new BlueToothHelper1(this,mBluetoothAdapter);
    }


    @Override
    public void onScanStarted() {
//        LogUtil.showLogD(TAG,"开始扫描");
    }

    @Override
    public void onDeviceFound(BluetoothDevice device) {
//        LogUtil.showLogD(TAG,"搜索到设备");
//        blueToothHelper.removeOnBlueScanListener(this);
//        blueToothHelper.pair(this,device);
    }

    @Override
    public void onScanFinished() {
//        LogUtil.showLogD(TAG,"扫描结束");
    }

    @Override
    public void onBondStateChanged(BluetoothDevice device,int oldState, int newState) {
//        LogUtil.showLogD(TAG,"绑定状态："+newState);
//        if (newState == BluetoothDevice.BOND_NONE &&
//                oldState == BluetoothDevice.BOND_BONDING) {
////            blueToothHelper.removeOnBondStateChanedListener(this);
//           LogUtil.showLogD(TAG,"【"+device.getName()+"】绑定失败");
//        } else if (newState == BluetoothDevice.BOND_BONDED) {
////            blueToothHelper.removeOnBondStateChanedListener(this);
//            LogUtil.showLogD(TAG,"【"+device.getName()+"】绑定成功");
//            blueToothHelper.connect(this,device,mBluetoothAdapter);
//        }
    }

    @Override
    protected void onDestroy() {
        LogUtil.showLogD(TAG,"app退出");
        super.onDestroy();
        blueToothHelper.removeAllReceiver(this);
    }
}